package com.hbnu.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Construction;
import com.hbnu.system.model.entity.Constructionfile;
import com.hbnu.system.service.IConstructionService;
import com.hbnu.system.service.IConstructionfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/construction")
@Api(tags = "学科建设模块")
public class ConstructionController {

    @Autowired
    IConstructionService iConstructionService;

    @Autowired
    IConstructionfileService iConstructionfileService;
    @ApiOperation("学科建设-文件信息上传")
    @PostMapping("/addConstructionfile")
    public Rest<Boolean> addConstructionfile(@RequestBody Constructionfile constructionfile){
        boolean add = iConstructionfileService.addConstructionfile(constructionfile);
        return add ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-文件信息删除")
    @GetMapping("/DeleteConstructionfile")
    public Rest<Boolean> DeleteConstructionfile(String ID)throws IOException {
        boolean delete = iConstructionfileService.deletConstructionfile(ID);
        return delete ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-文件信息分页查询")
    @GetMapping ("/pageConstructionfileCondition")
    public Rest<List<Constructionfile>> pageConstructionConditionfile(String id){
        List<Constructionfile> page = iConstructionfileService.pageConstructionfile(id);
        return Rest.success(page);
    }


    @ApiOperation("学科建设-文件信息修改")
    @PostMapping("/updateConstructionfile")
    public Rest<Boolean> updateConstructionfile(@RequestBody Constructionfile constructionfile){
        boolean update = iConstructionfileService.updateConstructionfile(constructionfile);
        return update ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-录入")
    @PostMapping("/addConstruction")
    public Rest<Boolean> addConstruction(@RequestBody Construction construction){
        boolean add = iConstructionService.addConstruction(construction);
        return add ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-删除")
    @GetMapping("/DeleteConstruction")
    public Rest<Boolean> DeleteConstruction(String constructionID){
        boolean delete = iConstructionService.deleteConstruction(constructionID);
        return delete ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-修改")
    @PostMapping("/updateConstruction")
    public Rest<Boolean> updateConstruction(@RequestBody Construction construction){
        boolean update = iConstructionService.updateConstruction(construction);
        return update ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-提交")
    @GetMapping("/CommitConstruction")
    public Rest<Boolean> CommitConstruction(String constructionID){
        boolean commit = iConstructionService.CommitConstruction(constructionID);
        return commit ? Rest.success() : Rest.failed();
    }


    @ApiOperation("根据主键查询学科建设")
    @GetMapping("/GetConstructionById")
    public Rest<Construction> GetConstructionById(String constructionID){
        Construction construction = iConstructionService.getConstruction(constructionID);
        return Rest.success(construction);
    }


    @ApiOperation("学科建设-分页查询")
    @PostMapping ("/pageConstructionCondition")
    public Rest<CommonPage<Construction>> pageConstructionCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Construction> page = iConstructionService.pageCondition(searchTaskDTO);
        CommonPage<Construction> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }


    @ApiOperation("学科建设-校级通过")
    @GetMapping("/SchoolPassConstruction")
    public Rest<String> SchoolPassConstruction(@RequestHeader("X-Token") String token,String constructionID){
        Boolean b = iConstructionService.schoolCheckPass(token,constructionID);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("学科建设-校级打回")
    @PostMapping("/SchoolBackConstruction")
    public Rest<String> SchoolBackConstruction(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iConstructionService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("用户获取与自己相关的学科建设-分页")
    @PostMapping("/UserGetRelateConstruction")
    public Rest<CommonPage<Construction>> UserGetRelateConstruction(@RequestBody UserDTO userDTO){
        IPage<Construction> constructionIPage = iConstructionService.userGetRelateConstruction(userDTO);
        CommonPage<Construction> constructionCommonPage = CommonPage.restPage(constructionIPage);
        return Rest.success(constructionCommonPage);
    }


    @ApiOperation("校级管理员查看需要自己审核的学科建设-分页")
    @PostMapping("/SchoolUserGetConstruction")
    public Rest<CommonPage<Construction>> SchoolUserGetConstruction(@RequestBody UserDTO userDTO){
        IPage<Construction> constructionIPage = iConstructionService.schoolUserGetConstruction(userDTO);
        CommonPage<Construction> constructionCommonPage = CommonPage.restPage(constructionIPage);
        return Rest.success(constructionCommonPage);
    }


}

